/*
 * Copyright (C) 2023, KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
#include "horscreen.h"
#include "title.h"
#include "city.h"
#include "perhour.h"
#include "weekweather.h"
#include "onedayweather.h"
#include "lifestyle.h"
#include "information.h"
#include <QVBoxLayout>
#include <QScrollArea>
#include <QScrollBar>
#include "daemondbus.h"
#include "global/corevar.h"
#include "view/horscreen/allowlocation.h"
#include <window_management.hpp>
#include "windowmanage.hpp"
horscreen *horscreen::mutual = nullptr;

horscreen::horscreen(QWidget *parent) : QWidget(parent)
{
    ::kabase::WindowManage::getWindowId(&m_windowId);
    initInteraction();
    mutual = this;

    //主题框架
    /* 适配kysdk的窗管 */
    // kdk::kabase::WindowManagement::setWindowMotifHint(this->winId());
    ::kabase::WindowManage::removeHeader(this);

    //    setWindowFlags(Qt::FramelessWindowHint);
    this->setMinimumSize(900, 620); 
    this->setWindowTitle(tr("Weather"));
    this->setFocusPolicy(Qt::ClickFocus);

    this->initWidget();
    this->initConnect();
    this->initLayout();
    
    m_changeCity->getChangeCityButton()->installEventFilter(this);
    m_changeCity->getCollectCityButton()->installEventFilter(this);
    this->installEventFilter(this);
    m_title->installEventFilter(this);
    
    // 初始化界面大小
    this->initMainWidgetSize();
    
}

void horscreen::initWidget()
{
    m_pixmap = QPixmap(":/res/background/100.png");
    m_label = new QLabel(this);
    m_label->move(0, 0);
    m_label->setAlignment(Qt::AlignRight); // 设置背景图片从右侧开始显示

    // 信创平板添加
    m_hMainlayout = new QHBoxLayout();
    m_hlayout = new QHBoxLayout();
    m_vlayout = new QVBoxLayout();
    m_mainLayout = new QVBoxLayout(this);
    m_mainCityLayout = new QVBoxLayout();
    m_hCityLayout = new QHBoxLayout();

    m_title = new title(this);
    m_empty = new Empty(this);
    m_changeCity = new ChangeCityWidget(this);
    m_widget = new QWidget(this);
    m_cityL = new city(m_widget);
    m_city = new city(m_widget);
    m_cityR = new city(m_widget);

    //实例化动画对象（切入）
    m_animationL = new QPropertyAnimation(m_cityL, "geometry", this); //指定动画主角
    m_animationL->setDuration(400);                                    //动画时间
    // m_animationL->setEasingCurve(QEasingCurve::OutBounce);

    //实例化动画对象（切出）
    m_animation = new QPropertyAnimation(m_city, "geometry", this);
    m_animation->setDuration(400);
    // m_animation->setEasingCurve(QEasingCurve::OutBounce);

    //实例化动画对象（切入）
    m_animationR = new QPropertyAnimation(m_cityR, "geometry", this);
    m_animationR->setDuration(400);
    // m_animationR->setEasingCurve(QEasingCurve::OutBounce);

    m_scrollarea = new QScrollArea(this);
    m_scrollarea->setFocusPolicy(Qt::NoFocus); //设置焦点类型
    m_scrollarea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_scrollarea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    m_scrollarea->verticalScrollBar()->setProperty("drawScrollBarGroove", false);
    // 设置scrollarea背景透明
    QPalette scrollarea = m_scrollarea->palette();
    scrollarea.setColor(QPalette::Background, QColor(Qt::transparent));
    m_scrollarea->setPalette(scrollarea);
    m_scrollarea->setFrameShape(QFrame::NoFrame); // 设置滑动区无边框
    m_scrollwidget = new QWidget(m_scrollarea);
    m_scrollarea->setWidget(m_scrollwidget);
    //    m_scrollwidget->move(0, m_city->y() + m_city->height() +20);
    m_information = new information(m_scrollwidget);

    m_searchView = new SearchView(this);
    m_searchView->hide();
    m_searchView->move((this->width() - m_searchView->width()) / 2, (this->height() - m_searchView->height()) / 2);

    m_hintWidget = new PromptWidget(this);
    m_hintWidget->setVisible(false);

    m_titleSearchCityView = new TitleSearchCityView(this);
    m_titleSearchCityView->hide();

    m_bottomListView = new BottomListView(this);

    return;
}

void horscreen::initMainWidgetSize()
{
    switch (ViewVar::getInstance()->m_currentMode)
    {
        case CurrentMode::PCMode:
            slotChangePCMode();
            break;
        case CurrentMode::PadHMode:
            slotChangePadHMode();
            break;    
        case CurrentMode::PadVMode:
            slotChangePadVMode();
            break;
        default:
            slotChangePCMode();
            break;
    }
    return;
}

void horscreen::changeBackgroundImage(CurrentWeather m_currentWeather)
{
    QString code = m_currentWeather.cond_code;
    QString path = ":/res/background/" + code + ".png";
    m_pixmap = QPixmap(path);
    // m_pixmap = m_pixmap.scaled(m_label->width(), m_label->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
    QPixmap pixmap;

    switch (ViewVar::getInstance()->m_currentMode) {
    case CurrentMode::PadVMode:
        pixmap = m_pixmap.scaled( 1800 * (m_label->height() / 1240) + 200, m_label->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
        break;
    default:
        pixmap = m_pixmap.scaled(m_label->width(), m_label->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
        break;
    }
    m_label->setPixmap(pixmap);

    qDebug() << " ===== INFO ===== 更换背景 =====" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
}

void horscreen::initLayout()
{
    m_mainCityLayout->addWidget(m_widget);

    QHBoxLayout *hLayout1 = new QHBoxLayout;
    QHBoxLayout *hLayout2 = new QHBoxLayout;
    QHBoxLayout *hLayout3 = new QHBoxLayout;
    hLayout1->addWidget(m_changeCity);
    hLayout1->setContentsMargins(70, 0, 70, 0);
    hLayout2->addLayout(m_mainCityLayout);
    hLayout3->addWidget(m_scrollarea);
    hLayout3->setContentsMargins(70, 0, 70, 0);

    m_vlayout->setSpacing(0);
    m_vlayout->setMargin(0);
    m_vlayout->addLayout(hLayout1);
    m_vlayout->addLayout(hLayout2, 1);
    m_vlayout->addLayout(hLayout3, 2);
    // m_vlayout->addWidget(m_changeCity);
    // m_vlayout->addLayout(m_mainCityLayout, 1);
    // m_vlayout->addWidget(m_scrollarea, 2);
    // m_vlayout->addWidget(m_bottomListView);
    // m_vlayout->setContentsMargins(70, 0, 70, 0);

    m_hlayout->addStretch();
    m_hlayout->addWidget(m_bottomListView);
    m_hlayout->addStretch();

    m_mainLayout->setSpacing(0);
    m_mainLayout->setMargin(0);
    m_mainLayout->addWidget(m_title);
    m_mainLayout->addLayout(m_vlayout);
    m_mainLayout->addSpacing(15);
    m_mainLayout->addLayout(m_hlayout);
    m_mainLayout->setContentsMargins(0, 0, 0, 0);
    this->setLayout(m_mainLayout);
}

void horscreen::changeHeight(double detio)
{
    m_scrollwidget->resize(this->width() - 165, (210 + 280 + 170 + 170 ) );
    m_information->resize(m_scrollwidget->width(), m_scrollwidget->height());
    m_scrollarea->resize(m_scrollwidget->width(), m_scrollwidget->height());
}

void horscreen::keyPressEvent(QKeyEvent *event)
{
    if(event->modifiers() == Qt::ControlModifier&&event->key()==Qt::Key_E){
        qDebug()<<__LINE__<<__func__;
        m_title->m_searchLineEdit->setFocus();
    }
    // F1快捷键打开用户手册
    if (event->key() == Qt::Key_F1) {
        kdk::kabase::UserManualManagement userManualTest;
        if (!userManualTest.callUserManual("kylin-weather")) {
            qCritical() << "user manual call fail!";
        }
        return;
    }
}

void horscreen::showOrHideMainWindow()
{
    //规避方案-wayland环境下，天气的机制拿不到windowid，走qt的时候，wayland环境拿不到窗口状态，所以暂时设置标志位区分窗口是否应被拉起
    if (ViewVar::widgetIsShow) {
        ViewVar::widgetIsShow = false;
    } else {
        ViewVar::widgetIsShow = true;
    }
    if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
        if (ViewVar::widgetIsShow) {
            handleIconClickedSub(); //显示在屏幕中央
        } else {
            this->showMinimized();
        }
        return;
    }
    if (this->isHidden() || this->isMinimized()) {
        handleIconClickedSub(); //显示在屏幕中央
    } else {
        this->showMinimized();
    }
}

// show或hide搜索弹窗
void horscreen::showSearchView()
{
    if (m_searchView->isHidden()) {
        m_searchView->raise();
        m_searchView->show();
        emit searchClear();
        Interaction::getInstance()->loadCollectCity();
    } else {
        //发送信号给搜索界面-重置界面显示
        emit searchClear();
        m_searchView->hide();
    }
}

void horscreen::initInteraction()
{
    connect(Interaction::getInstance(), &Interaction::netUiShow, this,
            &horscreen::recieveNetSignal); //返回网络错误，给UI发信号
    connect(Interaction::getInstance(), &Interaction::serverUiShow, this,
            &horscreen::recieveNetSignal); //返回请求服务器错误，给UI发信号
    connect(Interaction::getInstance(), &Interaction::dataUiShow, this,
            &horscreen::recieveNetSignal); //返回数据解析错误，给UI发信号
    connect(Interaction::getInstance(), &Interaction::netTimeout, this, &horscreen::recieveNetSignal); //超时返回
    connect(Interaction::getInstance(), &Interaction::geoUiShow, this, &horscreen::geoUiShow);         //定位失败

    connect(Interaction::getInstance(), &Interaction::showCurrent, this, &horscreen::showCurrent); //接收当前城市信息
    connect(Interaction::getInstance(), &Interaction::showForcast, this, &horscreen::showForcast); //接收预测信息
    connect(Interaction::getInstance(), &Interaction::showLifeStyle, this,
            &horscreen::showLifeStyle); //接收生活指数信息
    connect(Interaction::getInstance(), &Interaction::showHourly, this,
            &horscreen::showHourly); //增加逐小时天气接口--临时
    connect(Interaction::getInstance(), &Interaction::closePro, this, &horscreen::closeActivated); //关闭程序-退出

    // 后端返回存在数据/搜索“”时
    connect(Interaction::getInstance(), &Interaction::searchUiShow, this, &horscreen::slotShowTitleSearchCityView);
    // 后端左右城市信息
    connect(Interaction::getInstance(), &Interaction::sigShowLAndRCityInfo, this, &horscreen::slotGetLAndRCity);

}

void horscreen::initConnect()
{
    //最大化和还原
    //全屏按钮注释代码
    connect(m_title, &title::recovery, this, &horscreen::changOrigSize);
    // connect(m_city->m_changeCityBtn, &QPushButton::clicked, this,
    //         &horscreen::showSearchView); //搜索-添加城市弹窗显隐，按钮text变化
    connect(m_changeCity->getChangeCityButton(), &QPushButton::clicked, this, &horscreen::showSearchView); //搜索-添加城市弹窗显隐，按钮text变化
    connect(m_searchView, &SearchView::searchWidState, this, &horscreen::showSearchView); //点击切换城市后的主界面处理
    connect(this, &horscreen::searchClear, m_searchView, &SearchView::searchReset); //搜索弹窗界面重置

    //当前城市信息
    connect(this, &horscreen::sendCurrentInfor, m_city, &city::getCurrentInfor);
    connect(this, &horscreen::sendCurrentInfor, m_changeCity, &ChangeCityWidget::getCurrentInfor);
    //当前城市天气对应的背景图
    connect(this, &horscreen::sendCurrentInfor, this, &horscreen::changeBackgroundImage);
    // lifestyle
    connect(this, &horscreen::sendLifeStyleInfor, m_information, &information::getLifeStyleInfor);
    // 发送信号到 information->onehourweather/onehourweather/lifestyle,判断是全屏还是普通界面
    connect(this, &horscreen::sendIsFullScreen, m_information, &information::sendIsFullScreen);
    //全屏后的 city 布局
    connect(this, &horscreen::sendIsFullScreen, m_city, &city::isFullScreen);
    connect(this, &horscreen::sendIsFullScreen, m_changeCity, &ChangeCityWidget::isFullScreen);
    //当前城市放大缩小
    // connect(this, &horscreen::sendDetio, m_city, &city::initLayout);
    //当前城市上方空白widget放大缩小
    connect(this, &horscreen::sendDetio, m_empty, &Empty::resizeLayout);
    // 逐小时信息
    connect(this, &horscreen::sendHourlyInfor, m_information, &information::sendHourlyInfor);
    // 7周内天气信息
    connect(this, &horscreen::sendForcastInfor, m_information, &information::sendForcastInfor);
    // 7天预测天气图标放大缩小
    connect(this, &horscreen::sendWeatherIconInfor, m_information, &information::weekWeatherIcon);
    // 网络异常弹窗
    connect(this, &horscreen::recallInitLayout, m_hintWidget, &PromptWidget::initLayout);
    //    connect(m_city->m_changeCityBtn,&QPushButton::clicked,m_hintWidget,&PromptWidget::test);
    //    connect(this,&horscreen::recallInitLayout,m_hintWidget,&PromptWidget::test);
    connect(this, &horscreen::showCenterAfter, Interaction::getInstance(),
            &Interaction::showCenterAfter); //在屏幕中间显示

    connect(this, &horscreen::sendIsFullScreen, m_hintWidget, &PromptWidget::isFullScreen);

    connect(this, &horscreen::changeLoadingIconToButton, m_hintWidget, &PromptWidget::changeLoadingIconToButton);

    connect(m_title, &title::sigLineEditGetFocus, m_searchView, &SearchView::hide);
    
    connect(m_title, &title::sigTitleSearchCity, this, [=](){
        m_titleSearchCityView->setViewModel(false);
    });
    connect(this, &horscreen::sigTitleLineEditClear, m_title, &title::slotSearchLineEditClear);
    // connect(m_titleSearchCityView, &TitleSearchCityView::searchWidState, this, &horscreen::slotShowTitleSearchCityViewUi);//点击切换城市后的主界面处理
    connect(m_titleSearchCityView, &TitleSearchCityView::cityListNull, this, &horscreen::slotShowTitleSearchCityView);//点击切换城市后的主界面处理
    connect(m_titleSearchCityView, &TitleSearchCityView::sigTitleSearchChangeCityToMain, m_title, &title::slotSearchLineEditClear);
    connect(m_titleSearchCityView, &TitleSearchCityView::sigTitleSearchChangeCityToMain, this, &horscreen::slotShowTitleSearchCityViewUi);

    connect(this, &horscreen::sigGetDataFromCore, m_changeCity, &ChangeCityWidget::changeCollectBtnIcon);
    connect(this, &horscreen::sigGetDataFromCore, m_title, &title::slotChangeLineEditStyle);
    //    // 首次允许定位弹窗点击“是”更改菜单内允许定位为“是”
    //    connect(m_AllowLocationwidget,&AllowLocation::setMenuModuleAllowLocationYes,m_title,&title::setMenuModuleAllowLocationYes);

    connect(ViewVar::getInstance(), &ViewVar::sigChangeModeToPc, this, &horscreen::slotChangePCMode);
    connect(ViewVar::getInstance(), &ViewVar::sigChangeModeToPadH, this, &horscreen::slotChangePadHMode);
    connect(ViewVar::getInstance(), &ViewVar::sigChangeModeToPadV, this, &horscreen::slotChangePadVMode);

    connect(m_animation, &QPropertyAnimation::finished, this, [=](){
        m_cityL->getCurrentInfor(m_leftCityWeather);
        // m_city->getCurrentInfor(m_currentCityWeather);
        m_cityR->getCurrentInfor(m_rightCityWeather);
        m_animationBool = false;
    });
}

void horscreen::changOrigSize()
{
    if (this->isMaximized()) {
        ::kabase::WindowManage::removeHeader(this);
        this->showNormal();
        this->setFixedSize(900, 620);
        m_title->btnMaximum->setIcon(QIcon::fromTheme("window-maximize-symbolic")); //主题库的全屏图标
        m_title->btnMaximum->setToolTip(tr("full srceen"));
    } else {
        this->setMaximumSize(16777215, 16777215);
        this->showMaximized();
        m_title->btnMaximum->setIcon(QIcon::fromTheme("window-restore-symbolic")); //主题库的恢复图标
        m_title->btnMaximum->setToolTip(tr("recovery"));
        //全屏-埋点
        kdk::kabase::BuriedPoint buriedPointFullScreen;
        if (buriedPointFullScreen.functionBuriedPoint(kdk::kabase::AppName::KylinWeather,
                                                      kdk::kabase::BuriedPoint::PT::KylinWeatherFullScreen)) {
            qCritical() << "Error : buried point fail FullScreen!";
        };
    }
}

//不要删除
void horscreen::recieveNetSignal(QString netError)
{
    netErrorInfor = netError;
    //    showNetworkErrorDialog(netError);
    //    m_hintWidget->setVisible(true);
    //    m_hintWidget = new PromptWidget(this);
    //    m_hintWidget->setIconAndText(":/res/control_icons/network_warn.png", tr("Network not connected"));//网络未连接
    //    m_hintWidget->move((this->width() - m_hintWidget->width())/2, 70);
    //    m_hintWidget->setVisible(false);
    m_hintWidget->initLayout(netError, m_isFullScreen);
    m_mainCityLayout->removeWidget(m_widget);
    m_city->hide();

    m_mainCityLayout->addWidget(m_empty, 0, Qt::AlignCenter);
    m_mainCityLayout->addWidget(m_hintWidget, 0, Qt::AlignCenter);

    //    m_hintWidget->move((this->width() - m_hintWidget->width())/2, 70);
    isShow = true;
    //    m_hintWidget->setVisible(true);
    m_empty->setVisible(isShow);
    m_hintWidget->setVisible(isShow);

    emit changeLoadingIconToButton();

    // 搜索弹窗出现后，网络出现异常，异常提示界面弹出，搜索弹窗应该收回
    m_searchView->hide();
}

void horscreen::geoUiShow(QString geoError)
{
    QDBusInterface iface("org.freedesktop.Notifications", "/org/freedesktop/Notifications",
                         "org.freedesktop.Notifications", QDBusConnection::sessionBus());
    QList<QVariant> args;
    args << (tr("kylin-weather")) << ((unsigned int)0)
         << QString("/usr/share/icons/ukui-icon-theme-classical/128x128/apps/kylin-weather.png")
         << tr("kylin-weather") //显示的是什么类型的信息  控制面板-更新提示
         << geoError + tr("About to switch to default City") //显示的具体信息
         << QStringList() << QVariantMap() << (int)-1;

    iface.callWithArgumentList(QDBus::AutoDetect, "Notify", args);
}

void horscreen::showCurrent(CurrentWeather m_currentWeather)
{
    if (m_firstLoad) {
        Interaction::getInstance()->loadBottomCity();
    }
    
    qDebug() << " ##### Function Positioning ##### 城市信息显示 ##### " <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
    CoreVar::GET_CITY_INFO = true; 
    m_city->show();
    isShow = false;
    m_empty->setVisible(isShow);
    m_hintWidget->setVisible(isShow);

    m_mainCityLayout->removeWidget(m_empty);
    m_mainCityLayout->removeWidget(m_hintWidget);

    m_mainCityLayout->addWidget(m_widget, 0, Qt::AlignCenter);

    emit sendCurrentInfor(m_currentWeather);
    QString code = m_currentWeather.cond_code;
    //创建托盘图标
    //只有成功访问服务器且得到数据信息才显示托盘
    if (m_trayIcon != nullptr) {
        m_trayIcon->deleteLater();
    }
    createTrayIcon(code);
    // m_city->m_changeCityBtn->setEnabled(true);
    m_changeCity->getChangeCityButton()->setEnabled(true);
    m_changeCity->getCollectCityButton()->setEnabled(true);
    emit sigGetDataFromCore();
    getRightOrLeftCityID();
}

void horscreen::showForcast(ForecastWeather forecastWeather)
{
    emit sendForcastInfor(forecastWeather, m_isFullScreen);
    // 判断前面是否有网导致界面显示出正常天气信息
    // 0 : 使用过网络； 1 : 未使用过(初始值为 1)
    // 确保 emit sendWeatherIconInfor(m_isFullScreen);只有在 horscreen::showForcast
    // 发送过 emit sendForcastInfor(forecastWeather,m_isFullScreen);后才能发送
    if (usedNet == 1) {
        usedNet = 0;
    }
    // m_city->m_changeCityBtn->setEnabled(true);
    m_changeCity->getChangeCityButton()->setEnabled(true);
    m_changeCity->getCollectCityButton()->setEnabled(true);
}

void horscreen::showLifeStyle(LifeStyle m_lifeStyle)
{
    emit sendLifeStyleInfor(m_lifeStyle, m_isFullScreen);
}
//增加逐小时天气接口---临时用
void horscreen::showHourly(QVariant var)
{
    QList<Hourly> tmp_list = var.value<QList<Hourly>>();
    emit sendHourlyInfor(tmp_list, m_isFullScreen);
}
//创建托盘图标
void horscreen::createTrayIcon(QString code)
{
    if (ViewVar::platFormList.contains(ViewVar::platForm)) {
        return;
    }
    m_trayIcon = new QSystemTrayIcon(this);
    m_trayIcon->setToolTip(QString(tr("Weather")));
    QString trayPath = ":/res/weather-icon/PNG16/2x/" + code + ".png";
    m_trayIcon->setIcon(QIcon(trayPath));
    //    m_trayIcon->setIcon()
    //添加托盘菜单
    m_mainMenu = new QMenu;
    ::kabase::WindowManage::removeHeader(m_mainMenu);
    m_openAction = new QAction(tr("Open Weather"), this); //打开麒麟天气
    m_quitAction = new QAction(tr("Exit"), this);         //退出
    m_mainMenu->addAction(m_openAction);
    m_openAction->setIcon(QIcon::fromTheme(QString("kylin-weather")));
    m_mainMenu->addAction(m_quitAction);
    m_quitAction->setIcon(QIcon::fromTheme(QString("exit-symbolic")));

    m_trayIcon->setContextMenu(m_mainMenu);
    m_trayIcon->show();

    connect(m_openAction, &QAction::triggered, this, [=] {
        if (this->isHidden() || this->isMinimized()) {
            handleIconClickedSub();
            Interaction::getInstance()->showCenterAfter();
            //            emit showCenterAfter();
        } else {
            return;
        }
    });
    //    connect(this,&horscreen::showInCenter,Interaction::getInstance,&Interaction::showInCenter);//在屏幕中间显示
    connect(m_quitAction, &QAction::triggered, this, &horscreen::closeActivated);
    connect(m_trayIcon, &QSystemTrayIcon::activated, this, &horscreen::iconActivated);
}

void horscreen::handleIconClickedSub()
{
    if (this->m_title->g_menu->m_aboutWindow) {
        this->m_title->g_menu->m_aboutWindow->close();
    }
    this->hide();
    ::kabase::WindowManage::removeHeader(this);
    this->show();
    // wayland下居中显示
    if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
        ::kabase::WindowManage::setMiddleOfScreen(this);
    } else {
        QDesktopWidget *m = QApplication::desktop();
        QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos()));
        int desk_x = desk_rect.width();
        int desk_y = desk_rect.height();
        int x = this->width();
        int y = this->height();
        this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
    }
    ::kabase::WindowManage::removeHeader(this);
    this->activateWindow();
    this->raise();
    ViewVar::widgetIsShow = true;
    showLocateWidget();
}

//托盘图标被点击
void horscreen::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
    switch (reason) {
    case QSystemTrayIcon::Trigger:
    case QSystemTrayIcon::MiddleClick:
        this->showOrHideMainWindow();
        break;
    case QSystemTrayIcon::DoubleClick:
        this->showOrHideMainWindow();
        break;
    case QSystemTrayIcon::Context:
        //右键点击托盘图标弹出菜单
        // showTrayIconMenu(); //显示右键菜单
        m_mainMenu->show();
        break;
    default:
        break;
    }
}

void horscreen::closeActivated()
{
    //托盘退出默认关闭开机自启
    QString autostart =
        QStandardPaths::standardLocations(QStandardPaths::HomeLocation)[0] + "/.config/autostart/kylin-weather.desktop";
    QFile file(autostart);
    if (!file.exists()) {
        QString path = "/etc/xdg/autostart/kylin-weather.desktop";
        QFileInfo file2(path);
        if (!file2.exists()) {
            qDebug() << "/etc/xdg/autostart/目录下无麒麟天气快捷方式";
        } else {
            QFile::copy(path, autostart);
            if (file.exists()) {
                if (file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) {
                    file.write("\nHidden=true\n");
                    file.close();
                }
            }
        }
    }
    qApp->quit();
    return;
}

void horscreen::showLocateWidget()
{
    if (CoreVar::getSettings("locate-widget").toString() == "0" && this->isVisible()) {
        if (m_AllowLocationwidget == nullptr) {
            m_AllowLocationwidget = new AllowLocation(this);
            connect(m_AllowLocationwidget, &AllowLocation::setMenuModuleAllowLocationYes, m_title,
                    &title::setMenuModuleAllowLocationYes);
            m_AllowLocationwidget->resize(350, 174);
        }
        //暂时规避方案
        QTimer *timer = new QTimer;
        timer->setSingleShot(true);
        connect(timer, &QTimer::timeout, this, &horscreen::showAllowLocationWidget);
        connect(timer, &QTimer::timeout, timer, &QTimer::deleteLater);
        timer->start(500);
    }
}

void horscreen::showAllowLocationWidget()
{
    m_AllowLocationwidget->move(this->geometry().center() - m_AllowLocationwidget->rect().center());
    ::kabase::WindowManage::removeHeader(m_AllowLocationwidget);
    m_AllowLocationwidget->show();
}

//不要删--resize事件，使搜索弹窗可随主窗体尺寸变化而变化
void horscreen::resizeEvent(QResizeEvent *event)
{
    //    initLayout();
    if ((ViewVar::getInstance()->m_currentMode == CurrentMode::PCMode)) {
        m_isFullScreen = 0;
    } else if ((ViewVar::getInstance()->m_currentMode == CurrentMode::PadHMode)) {
        m_isFullScreen = 1;
    }  else if ((ViewVar::getInstance()->m_currentMode == CurrentMode::PadVMode)) {
        m_isFullScreen = 1;
    } 

    Q_UNUSED(event);
    m_searchView->move((this->width() - m_searchView->width()) / 2, (this->height() - m_searchView->height()) / 2);
    detio = double(this->height()) / 620;
    changeHeight(detio);
    m_label->resize(this->width(), this->height());
    QPixmap pixmap;
    switch (ViewVar::getInstance()->m_currentMode) {
    case CurrentMode::PadVMode:
        pixmap = m_pixmap.scaled(1800 * (m_label->height() / 1240) + 200 , m_label->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
        break;
    default:
        pixmap = m_pixmap.scaled(m_label->width(), m_label->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
        break;
    }
    
    m_label->setPixmap(pixmap);

    emit sendDetio(detio);
    emit sendIsFullScreen(m_isFullScreen);
    if (usedNet == 0) {
        emit sendWeatherIconInfor(m_isFullScreen);
    }
    // 如果网络提示界面是显示状态，则重新调用 PromptWidget::initLayout
    if (isShow == true) {
        m_hintWidget->initLayout(netErrorInfor, m_isFullScreen);
    }
    showLocateWidget();
}

//不要删--event事件，使搜索弹窗可在界面内失焦关闭
bool horscreen::event(QEvent *event)
{
    //点击别处，使搜索框失去焦点
    // if (event->type() == QEvent::MouseButtonPress
    //     && (!m_searchView->geometry().contains(this->mapFromGlobal(QCursor::pos())))) {
    //     //发送信号给搜索界面-重置界面显示
    //     emit searchClear();
    //     m_searchView->hide();
    //     // m_city->m_changeCityBtn->setText(tr("【Change】"));
    // }
    return QWidget::event(event);
}

void horscreen::hideSearchView()
{
    showSearchView();
}

void horscreen::slotShowTitleSearchCityView(bool hasCity)
{
    // 判断是否为标题栏的搜索进行的搜索
    if (!ViewVar::m_isTitleSearch) {
        // 当前搜索不是标题栏进行搜索，直接返回
        return;
    }
    if (hasCity) {
        QPoint globalPox = m_title->mapToGlobal(QPoint(0, 0));
        int x = (this->width() * 0.5) - (m_titleSearchCityView->width() * 0.5) - 15;
        int y = this->m_title->height();

        m_titleSearchCityView->move(x, y);
        m_titleSearchCityView->show();
    } 
    m_titleSearchCityView->searchUiChange(hasCity);
    m_titleSearchCityView->setViewModel(hasCity);
    
    return;
}

void horscreen::slotShowTitleSearchCityViewUi()
{
    m_titleSearchCityView->hide();
    return;
}

bool horscreen::eventFilter(QObject *watch, QEvent *e)
{
    if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::FocusIn) {
        if (watch != m_searchView && watch != m_changeCity->getChangeCityButton() && (!m_searchView->geometry().contains(this->mapFromGlobal(QCursor::pos())))) {
            //发送信号给搜索界面-重置界面显示
            emit searchClear();
            m_searchView->hide();
        }
    }
    
    // 鼠标点击位置不是搜索列表，发出信号，搜索框内容清空
    // 先判断当前是否进行标题栏搜索
    if (ViewVar::m_isTitleSearch) { 
        // 判断触发点击事件的对象是否为搜索区域
        if (watch != m_titleSearchCityView &&  e->type() == QEvent::MouseButtonPress) {
            slotShowTitleSearchCityViewUi();
            emit sigTitleLineEditClear();
        }
    }

    static int press_x;  //鼠标按下时的位置
    static int press_y;
    static int relea_x;  //鼠标释放时的位置
    static int relea_y;

    if (!CoreVar::GET_CITY_INFO) {
        return QObject::eventFilter(watch, e);
    }

    if (m_animationBool) {
        return QObject::eventFilter(watch, e);
    }
    if (m_city->isHidden()) {
        return QObject::eventFilter(watch, e);
    }
    
    QMouseEvent *event = static_cast<QMouseEvent *>(e); //将之转换为鼠标事件
    //如果鼠标按下
    if(event->type()==QEvent::MouseButtonPress) {
        move_x = QCursor::pos().x();
        press_x = event->globalX();
        press_y = event->globalY();
        if (watch == this) {
            getRightOrLeftCityID();
        }
    }
    //如果鼠标释放
    if(event->type()==QEvent::MouseButtonRelease) {
        relea_x = event->globalX();
        relea_y = event->globalY();
        // getRightOrLeftCityID();
    }
    if (event->type() == QEvent::MouseMove) {
        move_distancex = QCursor::pos().x() - move_x;
        if (qAbs(move_distancex) > m_widget->width()) {
            return QObject::eventFilter(watch, e);
        }
        /* 
          【界面滑动限制情况】
           当前无定位 + 无收藏城市 + 当期显示城市为其他 || 当前无定位 + 收藏城市 = 1 + 当前为收藏城市 || 当前为定位 + 无收藏城市
        */
        if ((CoreVar::LOCATION_CITY_ID == "" && CoreVar::CURRENT_CITY_TYPE == CityType::Other && CoreVar::CURRENT_COLLECT_LIST.size() - 1 == 0) || 
            (CoreVar::LOCATION_CITY_ID == "" && CoreVar::CURRENT_CITY_TYPE != CityType::Other && CoreVar::CURRENT_COLLECT_LIST.size() - 1 == 1) ||
            (CoreVar::LOCATION_CITY_ID != "" && CoreVar::CURRENT_COLLECT_LIST.size() - 1 == 0) ) {
            if ((move_distancex > 0 && move_distancex > m_widget->width() / 3) || (move_distancex < 0 && qAbs(move_distancex) > m_widget->width() / 4)) {
                return QObject::eventFilter(watch, e);
            }
            m_city->move(move_distancex, 0);
        } else {
            m_cityL->move(-m_widget->width() + move_distancex, 0);
            m_city->move(move_distancex, 0);
            m_cityR->move(m_widget->width() + move_distancex, 0);
        }
        qDebug() << QCursor::pos().x() << move_x << move_distancex;
    }
    if (qAbs(move_distancex) == 0 ) {
        return QObject::eventFilter(watch, e);
    }

    //判断滑动方向（向右滑）
    if((move_distancex)>100 && event->type()==QEvent::MouseButtonRelease) {
        if ((CoreVar::LOCATION_CITY_ID == "" && CoreVar::CURRENT_CITY_TYPE == CityType::Other && CoreVar::CURRENT_COLLECT_LIST.size() - 1 == 0) || 
            (CoreVar::LOCATION_CITY_ID == "" && CoreVar::CURRENT_CITY_TYPE != CityType::Other && CoreVar::CURRENT_COLLECT_LIST.size() - 1 == 1) ||
            (CoreVar::LOCATION_CITY_ID != "" && CoreVar::CURRENT_COLLECT_LIST.size() - 1 == 0) ) {
            setAnimationOnlyCity();
        } else {
            CoreVar::CURRENT_CITY_TYPE = m_leftCityType;
            Interaction::getInstance()->changeCityFromTitleSearch(m_leftCity);
            setLeftAnimation();
        }
        qDebug() << " 向 -> 滑 显示左边 " << m_leftCity << CoreVar::CURRENT_CITY_TYPE << move_distancex;
        move_distancex = 0;
    }
    //判断滑动方向（左滑）
    if((move_distancex) < -100 && event->type()==QEvent::MouseButtonRelease) {
        if ((CoreVar::LOCATION_CITY_ID == "" && CoreVar::CURRENT_CITY_TYPE == CityType::Other && CoreVar::CURRENT_COLLECT_LIST.size() - 1 == 0) || 
            (CoreVar::LOCATION_CITY_ID == "" && CoreVar::CURRENT_CITY_TYPE != CityType::Other && CoreVar::CURRENT_COLLECT_LIST.size() - 1 == 1) ||
            (CoreVar::LOCATION_CITY_ID != "" && CoreVar::CURRENT_COLLECT_LIST.size() - 1 == 0) ) {
            setAnimationOnlyCity();
        } else {
            CoreVar::CURRENT_CITY_TYPE = m_rightCityType;
            Interaction::getInstance()->changeCityFromTitleSearch(m_rightCity);
            setRightAnimation();
        }
        qDebug() << " 向 ← 滑 显示右边 " << m_rightCity << CoreVar::CURRENT_CITY_TYPE << move_distancex;
        move_distancex = 0;
    }
    if ((qAbs(move_distancex) > 0 && qAbs(move_distancex) < 100) && event->type()==QEvent::MouseButtonRelease) {
        qDebug() << relea_x - press_x ;
        setRevertAnimation();
        move_distancex = 0;
    }

    return QObject::eventFilter(watch, e);
}

void horscreen::getRightOrLeftCityID()
{
    if (CoreVar::CURRENT_CITY_ID == "") {
        // 如果当前城市ID为空，设置当前城市为北京，城市类别其他类别
        CoreVar::CURRENT_CITY_ID = CoreVar::DEFAULT_CITYID;
        // 判断当前城市是否为定位城市
        if (CoreVar::LOCATION_CITY_ID == CoreVar::DEFAULT_CITYID) {
            CoreVar::CURRENT_CITY_TYPE = CityType::Location;
        } else {
            if (CoreVar::CURRENT_COLLECT_LIST.contains(CoreVar::CURRENT_CITY_ID)) {
                CoreVar::CURRENT_CITY_TYPE = CityType::Collection;
            } else {
                CoreVar::CURRENT_CITY_TYPE = CityType::Other;
            }
        }
    }

    QString nowCity = CoreVar::CURRENT_CITY_ID; // 当前城市
    QString rightCity = CoreVar::CURRENT_CITY_ID; // 右侧城市
    QString leftCity = CoreVar::CURRENT_CITY_ID; // 左侧城市
    QStringList list = CoreVar::CURRENT_COLLECT_LIST;

    int listLen = list.size() - 1;
    int endListPos = listLen - 1;//(-2)，最后一个为空 ： “1010101000，”
    int position = list.indexOf(nowCity);
    CityType changeShowCityTypeLeft = CityType::None;
    CityType changeShowCityTypeRight = CityType::None;

    // 收藏列表中存在收藏城市“1010101000，”（2个城市）
    if (listLen < 2) {
        switch (CoreVar::CURRENT_CITY_TYPE) {
            case CityType::Location:
            qDebug() << " ===== INFO ===== CURRENT_CITY_TYPE = Location =====" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
            if (listLen > 0) { // 收藏城市不为空
                leftCity = CoreVar::CURRENT_COLLECT_LIST.at(0);
                rightCity = CoreVar::CURRENT_COLLECT_LIST.at(0);
                changeShowCityTypeLeft = CityType::Collection; // 左边为收藏城市
                changeShowCityTypeRight = CityType::Collection; // 右边为收藏城市
            } else { // 收藏城市为空
                leftCity = CoreVar::CURRENT_CITY_ID;
                rightCity = CoreVar::CURRENT_CITY_ID;
                changeShowCityTypeLeft = CoreVar::CURRENT_CITY_TYPE; // 左边为当前城市类别
                changeShowCityTypeRight = CoreVar::CURRENT_CITY_TYPE; // 右边为当前城市类别
            }
                break;
            case CityType::Other:
            qDebug() << " ===== INFO ===== CURRENT_CITY_TYPE = Other =====" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
                // 定位城市为空
                if (CoreVar::LOCATION_CITY_ID == "") {
                    if (listLen > 0) { // 收藏城市不为空
                        leftCity = CoreVar::CURRENT_COLLECT_LIST.at(0);
                        rightCity = CoreVar::CURRENT_COLLECT_LIST.at(0);
                        changeShowCityTypeLeft = CityType::Collection; // 左边为收藏城市
                        changeShowCityTypeRight = CityType::Collection; // 右边为收藏城市
                    } else { // 收藏城市为空
                        leftCity = CoreVar::CURRENT_CITY_ID;
                        rightCity = CoreVar::CURRENT_CITY_ID;
                        changeShowCityTypeLeft = CoreVar::CURRENT_CITY_TYPE; // 左边为当前城市类别
                        changeShowCityTypeRight = CoreVar::CURRENT_CITY_TYPE; // 右边为当前城市类别
                    }
                } else { // 存在定位城市
                    if (listLen > 0) { // 收藏城市不为空
                        leftCity = CoreVar::CURRENT_COLLECT_LIST.at(0);
                        rightCity = CoreVar::LOCATION_CITY_ID;
                        changeShowCityTypeLeft = CityType::Collection; // 左边为收藏城市
                        changeShowCityTypeRight = CityType::Location; // 右边为定位城市
                    } else { // 收藏城市为空
                        leftCity = CoreVar::LOCATION_CITY_ID;
                        rightCity = CoreVar::LOCATION_CITY_ID;
                        changeShowCityTypeLeft = CityType::Location; // 左边为定位城市
                        changeShowCityTypeRight = CityType::Location; // 右边为定位城市
                    }
                }
                break;
            case CityType::Collection:
            qDebug() << " ===== INFO ===== CURRENT_CITY_TYPE = Collection =====" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
                // 定位城市为空
                if (CoreVar::LOCATION_CITY_ID == "") {
                    leftCity = CoreVar::CURRENT_COLLECT_LIST.at(0);
                    rightCity = CoreVar::CURRENT_COLLECT_LIST.at(0);
                    changeShowCityTypeLeft = CityType::Collection; // 左边为收藏城市
                    changeShowCityTypeRight = CityType::Collection; // 右边为收藏城市
                } else { // 存在定位城市
                    leftCity = CoreVar::LOCATION_CITY_ID;
                    rightCity = CoreVar::LOCATION_CITY_ID;
                    changeShowCityTypeLeft = CityType::Location; // 左边为定位城市
                    changeShowCityTypeRight = CityType::Location; // 右边为定位城市
                }
                
                break;
            default:
                leftCity = CoreVar::LOCATION_CITY_ID;
                rightCity = CoreVar::LOCATION_CITY_ID;
                changeShowCityTypeLeft = CityType::Location; // 左边为定位城市
                changeShowCityTypeRight = CityType::Location; // 右边为定位城市
                break;
        }
        m_leftCity = leftCity;
        m_rightCity = rightCity;
        m_leftCityType = changeShowCityTypeLeft;
        m_rightCityType = changeShowCityTypeRight;
        QString cityLAndR = leftCity + "," + CoreVar::CURRENT_CITY_ID + "," + rightCity;
        Interaction::getInstance()->getLAndRCityInfo(cityLAndR);
        return;
    }
    // 收藏列表中存在收藏城市“1010101000,101030100, ”（3个城市）
    switch (CoreVar::CURRENT_CITY_TYPE) {
        // 当前显示城市为定位城市(location)
        case CityType::Location:
            qDebug() << " ===== INFO ===== CURRENT_CITY_TYPE = Location =====" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__<<" =====  endListPos" << endListPos;
            /* 藏(end) 本地 藏(first) */ 
            rightCity = CoreVar::CURRENT_COLLECT_LIST.at(0);
            leftCity = CoreVar::CURRENT_COLLECT_LIST.at(endListPos);
            changeShowCityTypeLeft = CityType::Collection; // 左边为收藏城市
            changeShowCityTypeRight = CityType::Collection; // 右边为收藏城市
            break;
        // 当前显示城市为搜索城市(other)
        case CityType::Other:
            qDebug() << " ===== INFO ===== CURRENT_CITY_TYPE = Other =====" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__<<" =====  endListPos" << endListPos;
            /* 藏(end) 搜索城市 (可能存在)本地 藏(first)  */ 
            if (CoreVar::LOCATION_CITY_ID != "") {
                //存在定位城市
                /*  藏(end) 搜索城市 本地   */
                rightCity = CoreVar::LOCATION_CITY_ID;
                changeShowCityTypeRight = CityType::Location;// 右边为本地城市
            } else {
                // 直接显示收藏城市
                /* 藏(end) 搜索城市 藏(first)  */ 
                rightCity = CoreVar::CURRENT_COLLECT_LIST.at(0);
                changeShowCityTypeRight = CityType::Collection; // 右边为收藏城市
            }
            leftCity = CoreVar::CURRENT_COLLECT_LIST.at(endListPos);
            changeShowCityTypeLeft = CityType::Collection; // 左边为收藏城市
            break;
        // 当前的城市为收藏城市中的一员
        case CityType::Collection:
        qDebug() << " ===== INFO ===== CURRENT_CITY_TYPE = Collection =====" <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__<<" ===== position " << position << " =====  endListPos" << endListPos;
            if (position < 0) {
                break;
            }
            if (position == endListPos) { 
                // 当前城市在收藏列表的位置为最后一位
                /* 藏(end-1) 【当前 藏(end)】 (可能存在)本地 藏(first)  */ 
                if (CoreVar::LOCATION_CITY_ID == "") {
                    /* 藏(end-1) 藏(end) 藏(first)  */ 
                    rightCity = CoreVar::CURRENT_COLLECT_LIST.at(0);
                    changeShowCityTypeRight = CityType::Collection; // 右边为收藏城市
                } else {
                    /* 藏(end-1) 藏(end) 本地 */ 
                    rightCity = CoreVar::LOCATION_CITY_ID;
                    changeShowCityTypeRight = CityType::Location; // 右边为本地城市
                }
                leftCity = CoreVar::CURRENT_COLLECT_LIST.at(position - 1);
                changeShowCityTypeLeft = CityType::Collection; // 左边为收藏城市
            } else if (position == 0) {
                // 当前城市在收藏列表的位置为第一位
                /* 藏(end) (可能存在)本地 【当前 藏(first)】 藏(end-1) */
                if (CoreVar::LOCATION_CITY_ID == "") {
                    /* 藏(end) 【当前 藏(first)】 藏(end-1) */ 
                    leftCity = CoreVar::CURRENT_COLLECT_LIST.at(endListPos);
                    changeShowCityTypeLeft = CityType::Collection;// 左边为收藏城市
                } else {   
                    /* 本地 【当前 藏(first)】 藏(end-1) */ 
                    leftCity = CoreVar::LOCATION_CITY_ID;
                    changeShowCityTypeLeft = CityType::Location;// 左边为收藏城市
                }
                rightCity = CoreVar::CURRENT_COLLECT_LIST.at(position + 1);
                changeShowCityTypeRight = CityType::Collection; // 右边为收藏城市
            } else {
                // 当前城市在收藏列表的位置为中间位置
                /* 藏 藏 藏 */
                rightCity = CoreVar::CURRENT_COLLECT_LIST.at(position + 1);
                leftCity = CoreVar::CURRENT_COLLECT_LIST.at(position - 1);
                changeShowCityTypeLeft = CityType::Collection; // 左边为收藏城市
                changeShowCityTypeRight = CityType::Collection; // 右边为收藏城市
            }
            break;
        default: 
            leftCity = CoreVar::CURRENT_CITY_ID;
            rightCity = CoreVar::CURRENT_CITY_ID;
            changeShowCityTypeLeft = CoreVar::CURRENT_CITY_TYPE;
            changeShowCityTypeRight = CoreVar::CURRENT_CITY_TYPE;
            break;
    }
    m_leftCity = leftCity;
    m_rightCity = rightCity;
    m_leftCityType = changeShowCityTypeLeft;
    m_rightCityType = changeShowCityTypeRight;

    QString cityLAndR = leftCity + "," + CoreVar::CURRENT_CITY_ID + "," + rightCity;
    Interaction::getInstance()->getLAndRCityInfo(cityLAndR);

    return;
}

void horscreen::slotChangePCMode()
{
    this->setFixedSize(900, 620);
    m_widget->setFixedSize(this->width(), 200);
    m_cityL->setFixedSize(this->width(), 200);
    m_city->setFixedSize(this->width(), 200);
    m_cityR->setFixedSize(this->width(), 200);
    m_cityL->slotChangePCMode();
    m_city->slotChangePCMode();
    m_cityR->slotChangePCMode();
    m_cityL->move(-this->width(), 0);
    m_cityR->move(this->width(), 0);
    this->showMaximized();
    if (ViewVar::widgetIsShow == false){
        this->hide();
    }
    return;
}

void horscreen::slotChangePadHMode()
{
    this->setFixedSize(ViewVar::getInstance()->m_currentSize.first,ViewVar::getInstance()->m_currentSize.second);
    m_widget->setFixedSize(this->width(), 200);
    m_cityL->setFixedSize(this->width(), 200);
    m_city->setFixedSize(this->width(), 200);
    m_cityR->setFixedSize(this->width(), 200);
    m_cityL->slotChangePadHMode();
    m_city->slotChangePadHMode();
    m_cityR->slotChangePadHMode();
    m_cityL->move(-this->width(), 0);
    m_cityR->move(this->width(), 0);
    return;
}

void horscreen::slotChangePadVMode()
{
    this->setFixedSize(ViewVar::getInstance()->m_currentSize.first,ViewVar::getInstance()->m_currentSize.second);
    m_widget->setFixedSize(this->width(), 200);
    m_cityL->setFixedSize(this->width(), 200);
    m_city->setFixedSize(this->width(), 200);
    m_cityR->setFixedSize(this->width(), 200);
    m_cityL->slotChangePadVMode();
    m_city->slotChangePadVMode();
    m_cityR->slotChangePadVMode();
    m_cityL->move(-this->width(), 0);
    m_cityR->move(this->width(), 0);
    return;
}

void horscreen::setRevertAnimation()
{
    m_animationL->setStartValue(QRect(m_cityL->pos().x(), 0, m_widget->width(), m_widget->height())); //动画起始位置
    m_animationL->setEndValue(QRect(-m_widget->width(), 0, m_widget->width(), m_widget->height()));
    m_animation->setStartValue(QRect(m_city->pos().x(), 0, m_widget->width(), m_widget->height()));
    m_animation->setEndValue(QRect(0, 0, m_widget->width(), m_widget->height()));  //动画结束位置
    m_animationR->setStartValue(QRect(m_cityR->pos().x(), 0, m_widget->width(), m_widget->height())); //动画起始位置
    m_animationR->setEndValue(QRect(m_widget->width(), 0, m_widget->width(), m_widget->height()));   //动画结束位置
    
    QParallelAnimationGroup *group = new QParallelAnimationGroup();
    group->addAnimation(m_animation);
    group->addAnimation(m_animationR);
    group->addAnimation(m_animationL);
    group->start();
    m_animationBool = true;
    return;
}

void horscreen::setRightAnimation()
{
    m_animationL->setStartValue(QRect(m_city->pos().x(), 0, m_widget->width(), m_widget->height())); //动画起始位置
    m_animationL->setEndValue(QRect(-m_widget->width(), 0, m_widget->width(), m_widget->height()));
    m_animation->setStartValue(QRect(m_widget->width() + m_city->pos().x() , 0, m_widget->width(), m_widget->height()));
    m_animation->setEndValue(QRect(0, 0, m_widget->width(), m_widget->height())); //动画结束位置
    m_animationR->setStartValue(QRect(m_widget->width(), 0, m_widget->width(), m_widget->height())); //动画起始位置
    m_animationR->setEndValue(QRect(m_widget->width(), 0, m_widget->width(), m_widget->height()));  //动画结束位置
    changeCityRight();
    getRightOrLeftCityID();
    return;
}

void horscreen::setLeftAnimation()
{
    m_animationL->setStartValue(QRect(-m_widget->width(), 0, m_widget->width(), m_widget->height())); //动画起始位置
    m_animationL->setEndValue(QRect(-m_widget->width(), 0, m_widget->width(), m_widget->height()));
    m_animation->setStartValue(QRect(-m_widget->width() + m_city->pos().x(), 0, m_widget->width(), m_widget->height()));
    m_animation->setEndValue(QRect(0, 0, m_widget->width(), m_widget->height()));  //动画结束位置
    m_animationR->setStartValue(QRect(m_city->pos().x(), 0, m_widget->width(), m_widget->height())); //动画起始位置
    m_animationR->setEndValue(QRect(m_widget->width(), 0, m_widget->width(), m_widget->height()));   //动画结束位置
    changeCityLeft();
    getRightOrLeftCityID();
    return;
}

void horscreen::setAnimationOnlyCity()
{
    m_animation->setStartValue(QRect(m_city->pos().x(), 0, m_widget->width(), m_widget->height()));
    m_animation->setEndValue(QRect(0, 0, m_widget->width(), m_widget->height()));  //动画结束位置
    
    QParallelAnimationGroup *group = new QParallelAnimationGroup();
    group->addAnimation(m_animation);
    group->start();
    m_animationBool = true;
    return;
}

void horscreen::changeCityRight()
{
    m_city->getCurrentInfor(m_rightCityWeather);
    m_cityL->getCurrentInfor(m_currentCityWeather);

    QParallelAnimationGroup *group = new QParallelAnimationGroup();
    group->addAnimation(m_animationL);
    group->addAnimation(m_animation);
    group->addAnimation(m_animationR);
    group->start();
    m_animationBool = true;
    return;
}

void horscreen::changeCityLeft()
{
    m_city->getCurrentInfor(m_leftCityWeather);
    m_cityR->getCurrentInfor(m_currentCityWeather);

    QParallelAnimationGroup *group = new QParallelAnimationGroup();
    group->addAnimation(m_animationL);
    group->addAnimation(m_animation);
    group->addAnimation(m_animationR);
    group->start();
    m_animationBool = true;
    return;
}

void horscreen::slotGetLAndRCity(QList<CurrentWeather> cityList)
{
    qDebug() << " ===== INFO ===== " << cityList.at(0).city << cityList.at(1).city << cityList.at(2).city <<__FILE__<< ","<<__FUNCTION__<<","<<__LINE__;
    m_leftCityWeather = cityList[0];
    m_currentCityWeather = cityList[1];
    m_rightCityWeather = cityList[2];
    if (m_firstLoad) {
        m_firstLoad = false;
        m_cityR->getCurrentInfor(m_rightCityWeather);
        m_cityL->getCurrentInfor(m_leftCityWeather);
    }
    return;
}
